Telegram Group & Telegram Channel
134. Program to delete a node for a given element from linked list.

#include <stdio.h>
#include<stdlib.h>

typedef struct node {
int data;
struct node *next;
}Node;

int main(void)
{
Node*temp;
Node*start=NULL;
Node* p=NULL;

int n;
scanf("%d",&n);

while(n--)
{
temp=(Node *)malloc(sizeof(struct node));
scanf("%d",&temp->data);
temp->next=NULL;

if(start==NULL)
{
start=temp;
p=temp;
}
else
{
p->next=temp;
p=temp;
}
}

printf("Element to delete : ");
int ele; scanf("%d",&ele); printf("%d\n",ele);
Node*prev=start;
Node*cur=start;

while(cur!=NULL)
{
if(start->data==ele)
{
start=start->next;
}

if(cur->data==ele)
{
prev->next=cur->next;
free(cur);
break;
}
prev=cur;
cur=cur->next;

if(cur==NULL)
{
printf("Element doesn't exist!");
exit(0);
}
}

while(start!=NULL)
{
if(start->next!=NULL)
printf("%d->",start->data);
else
printf("%d",start->data);

start=start->next;
}

return 0;
}
#program_by : @freakyLuffy



tg-me.com/C_Codings/195
Create:
Last Update:

134. Program to delete a node for a given element from linked list.

#include <stdio.h>
#include<stdlib.h>

typedef struct node {
int data;
struct node *next;
}Node;

int main(void)
{
Node*temp;
Node*start=NULL;
Node* p=NULL;

int n;
scanf("%d",&n);

while(n--)
{
temp=(Node *)malloc(sizeof(struct node));
scanf("%d",&temp->data);
temp->next=NULL;

if(start==NULL)
{
start=temp;
p=temp;
}
else
{
p->next=temp;
p=temp;
}
}

printf("Element to delete : ");
int ele; scanf("%d",&ele); printf("%d\n",ele);
Node*prev=start;
Node*cur=start;

while(cur!=NULL)
{
if(start->data==ele)
{
start=start->next;
}

if(cur->data==ele)
{
prev->next=cur->next;
free(cur);
break;
}
prev=cur;
cur=cur->next;

if(cur==NULL)
{
printf("Element doesn't exist!");
exit(0);
}
}

while(start!=NULL)
{
if(start->next!=NULL)
printf("%d->",start->data);
else
printf("%d",start->data);

start=start->next;
}

return 0;
}
#program_by : @freakyLuffy

BY C Language πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/C_Codings/195

View MORE
Open in Telegram


C Language ‍ Telegram | DID YOU KNOW?

Date: |

Can I mute a Telegram group?

In recent times, Telegram has gained a lot of popularity because of the controversy over WhatsApp’s new privacy policy. In January 2021, Telegram was the most downloaded app worldwide and crossed 500 million monthly active users. And with so many active users on the app, people might get messages in bulk from a group or a channel that can be a little irritating. So to get rid of the same, you can mute groups, chats, and channels on Telegram just like WhatsApp. You can mute notifications for one hour, eight hours, or two days, or you can disable notifications forever.

However, analysts are positive on the stock now. β€œWe have seen a huge downside movement in the stock due to the central electricity regulatory commission’s (CERC) order that seems to be negative from 2014-15 onwards but we cannot take a linear negative view on the stock and further downside movement on the stock is unlikely. Currently stock is underpriced. Investors can bet on it for a longer horizon," said Vivek Gupta, director research at CapitalVia Global Research.

C Language ‍ from sa


Telegram C Language πŸ‘¨β€πŸ’»
FROM USA